package com.example.mobiledatapackage.controller;

import com.example.mobiledatapackage.domain.Package;
import com.example.mobiledatapackage.service.PackageService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.jena.rdf.model.*;
import org.apache.jena.reasoner.Reasoner;
import org.apache.jena.util.PrintUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Iterator;
import java.util.List;


@RestController
@RequestMapping("/test")
@Tag(name = "TestController", description = "一些开发过程中用于测试的东西")
public class TestController {

    @Autowired
    private InfModel infModel;

    @Autowired
    private PackageService packageService;

    @Autowired
    private Reasoner reasoner;

    @GetMapping("/hello")
    public String connectionTest(@RequestParam("name") String name) {
        return "Hello, " + name;
    }

    @GetMapping("/jena")
    public String jenaTest() {
        String personURI    = "http://somewhere/JohnSmith";
        Model model = ModelFactory.createDefaultModel();
        Resource johnSmith = model.createResource(personURI);
        return johnSmith.getURI();
    }

    @GetMapping("/gradle")
    public String helloGradle() {
        return "Hello, Gradle!";
    }

    @GetMapping("/inf")
    public String infModelTest() {
        Iterator<Statement> list = infModel.listStatements();
        PrintUtil.printOut(list);
        return "yes";
    }

    @GetMapping("/all")
    public List<Package> getPackages() {
        return packageService.selectAll();
    }

}
